package im.bobo.android.contact;

import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;

public class ContactsAdapter extends ResourceCursorAdapter {

	public ContactsAdapter(Context context, int layout, Cursor c) {
		
		super(context, layout, c);
		
	}

	@Override
	public void bindView(View paramView, Context context,
			Cursor paramCursor) {
		TextView nameText=(TextView) paramView.findViewById(android.R.id.text1);
		TextView telText=(TextView) paramView.findViewById(android.R.id.text2);
		nameText.setText(paramCursor.getString(paramCursor.getColumnIndex(Contacts.DISPLAY_NAME)));
		int id=paramCursor.getInt(paramCursor.getColumnIndex(Contacts._ID));
		Cursor cursor=context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?" ,new String[]{String.valueOf(id)} ,null);
		cursor.moveToNext();
		telText.setText(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)).replace("-", ""));
		cursor.close();

	}
	
	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
	  
		
		return super.newView(context, cursor, parent);
	}

}
